/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlets;

import dao.ListCategory;
import dao.ListInforCompany;
import dao.ListInforContact;
import dao.ListSearchVacancy;
import dao.ListVacancy;
import dao.ListWorkPlace;
import dao.loginDao;
import entities.Category;
import entities.InforCompany;
import entities.InforContact;
import entities.Vacancy;
import entities.WorkPlace;
import entities.login;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 *
 * @author Jung Jin Hyuk
 */
@WebServlet(name = "SendProfile", urlPatterns = {"/SendProfile"})
public class SendProfile extends HttpServlet {

    loginDao lgd = new loginDao();
    login lg = null;
    ListCategory daoCate = new ListCategory();
    ListWorkPlace daoWP = new ListWorkPlace();
    ListSearchVacancy daoVaHot = new ListSearchVacancy();
    ListInforCompany daoICP = new ListInforCompany();
    ListInforContact daoICT = new ListInforContact();
    ListVacancy daova = new ListVacancy();

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        List<Category> listC = daoCate.getListCategory();
        List<WorkPlace> listWP = daoWP.getListWorkPlace();

        String vId = request.getParameter("vId");

        Vacancy va = daova.getVacancy(vId);


        InforCompany cp = daoICP.getCompanyByVacancyId(vId);

        //Set contact by vacancy id
        InforContact ct = daoICT.getContactByVacancyId(vId);


        HttpSession session = request.getSession();

        if (session.getAttribute("username") != null) {
            request.setAttribute("v", va);
            request.setAttribute("cp", cp);
            request.setAttribute("ct", ct);

            request.setAttribute("listC", listC);
            request.setAttribute("listWP", listWP);
            //request.setAttribute("lisVa", lisva);
            request.getRequestDispatcher("user/SendProfile.jsp").forward(request, response);
        } else {
            request.setAttribute("listC", listC);
            request.setAttribute("listWP", listWP);
            request.getRequestDispatcher("user/login.jsp").forward(request, response);
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
